// grouponList.js
const regeneratorRuntime = require('../../lib/runtime');
const wx = require('../../lib/wx');
const Api = require('../../utils/api.js');
const wxapp = require('../../lib/wxapp');

// 获取应用实例
const app = getApp();
Page({
  data: {
    productList: [
      {
        imgUrl: '../../images/products/product_img1.png',
        url: '../productDetail/productDetail',
        people: 2,
        title: 'HABA',
        subTitle: '日本无添加主义 丝滑泡沫洁面皂 80g',
        description: '欧乐通旗舰店',
        current_price: '46.93',
        orign_price: '53.00',
        joined: 0,
      },
      {
        imgUrl: '../../images/products/product_img2.png',
        url: '../productDetail/productDetail',
        people: 2,
        title: 'HABA',
        subTitle: '日本无添加主义 润泽柔肤水（G露）180ml',
        description: '因淘优品',
        current_price: '168.00',
        orign_price: '189.00',
        joined: 1,
      },
      {
        imgUrl: '../../images/products/product_img3.png',
        url: '../productDetail/productDetail',
        people: 2,
        title: 'Whoo',
        subTitle: 'Whoo/后 拱辰享气韵生系列6件套礼盒',
        description: 'Whoo',
        current_price: '680.76',
        orign_price: '756.00',
        joined: 0,
      },
      {
        imgUrl: '../../images/products/product_img1.png',
        url: '../productDetail/productDetail',
        people: 2,
        title: 'HABA',
        subTitle: '日本无添加主义 丝滑泡沫洁面皂 80g',
        description: '欧乐通旗舰店',
        current_price: '46.93',
        orign_price: '53.00',
        joined: 0,
      },
      {
        imgUrl: '../../images/products/product_img2.png',
        url: '../productDetail/productDetail',
        people: 2,
        title: 'HABA',
        subTitle: '日本无添加主义 润泽柔肤水（G露）180ml',
        description: '因淘优品',
        current_price: '168.00',
        orign_price: '189.00',
        joined: 1,
      },
      {
        imgUrl: '../../images/products/product_img3.png',
        url: '../productDetail/productDetail',
        people: 2,
        title: 'Whoo',
        subTitle: 'Whoo/后 拱辰享气韵生系列6件套礼盒',
        description: 'Whoo',
        current_price: '680.76',
        orign_price: '756.00',
        joined: 0,
      },
    ],
  },

  goToDetail: wxapp.handler(function* goToDetail(next, e){
    const url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url,
    });

    yield next;
  }),

  goToMenu: wxapp.handler(function* goToMenu(next, e){
    const url = e.currentTarget.dataset.url;
    wx.reLaunch({
      url,
    });

    yield next;
  }),

  onShow: wxapp.handler(function* onShow(next) {

    yield next;
  }),

  onLoad: wxapp.handler(function* onLoad(next) {

    yield next;

    var getGroupList = Api.getGroupList();
    var that = this;

    // 首页banner
    wx.request({
      url: getGroupList,
      header: {
        'content-type': 'application/json'
      },
      method: 'GET',
      complete: function (res) {
        that.setData({ productList: res.data.data });
      }
    });
  }),

});
